//
//  UITableViewCell+drawImage.m
//  Finance
//
//  Created by cheng xiang on 13-8-21.
//  Copyright (c) 2013年 cheng xiang. All rights reserved.
//

#import "UITableViewCell+drawImage.h"

@implementation UITableViewCell (drawImage)

- (void)drawBankImage:(NSObject *)obj
{
    if ([obj isKindOfClass:[NSString class]]) {
        NSString *imageurl = (NSString *)obj;
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageurl]]];
        image = [self imageWithImage:image scaledToSize:CGSizeMake(20, 20)];
        [self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];
        [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
    }
}

-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    
    // Tell the old image to draw in this new context, with the desired
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    
    // Return the new image.
    return newImage;
}

@end
